let env = 0  // 1正式、0测试
/* 服务器地址 */
let base_url = ''
if (env == 1) {
    base_url = 'http://10.62.17.6:19901/' //正式服务器
} else {
    base_url = 'http://192.168.1.150:18080' //测试服务器
}

// 创建axios实例
const service = axios.create({
    baseURL: base_url, // api的base_url
    timeout: 120000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
    config.headers['Content-Type'] = "application/json;charset=UTF-8"
    // config.headers['Content-Type'] = "application/x-www-form-urlencoded"
    config.headers['Access-Control-Allow-Credentials'] = "true"
    config.headers['Authorization'] = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0bCN0eiIsImV4cCI6MTY1Njk4NjY3NjY0NSwiaWF0IjoxNjU2OTg0ODc2NjQ1fQ.4ndpx50_ShpY9abaDOLDc3PgMAGTcqomfV6lj1yUmno"
    
    return config
}, error => {
    Promise.reject(error)
})

// response拦截器
service.interceptors.response.use(
    response => {
        const res = response.data
        if(res.code == 200){
            return Promise.resolve(res)
        } else {
            console.log('response',response)
            return Promise.reject(res)
        }
    },
    error => {
        console.log(error) // for debug
        return Promise.reject(error)
    }
)
